﻿using UnityEngine;
class HitBoxBaseView : MonoBehaviour, IBaseView
{
    public CollisionEntity Collisionentity;

    protected void Awake()
    {
        Collisionentity = Contexts.sharedInstance.collision.CreateEntity();
        Collisionentity.AddBaseView(this);
        transform.parent = null;
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Enemy" && collision.isTrigger == true)
        {
            if (Collisionentity.owner.value != "Enemy")
            {
                if (!Collisionentity.hasTargetInformation)
                    Collisionentity.AddTargetInformation(collision.name, collision.GetComponent<EnemyView>().enemyEntity.contextInfo.name);
                ServiceManager.DebugMessageService.Print("Weapon has made contact");
                Destroy(gameObject);
            }
        }

        if (collision.tag == "Player" && collision.isTrigger == true)
        {
            if (Collisionentity.owner.value != "Player")
            {
                if (!Collisionentity.hasTargetInformation)
                {
                    Collisionentity.AddTargetInformation(collision.name, collision.GetComponent<PlayerView>().Player.contextInfo.name);
                    ServiceManager.DebugMessageService.Print("Enemy made a contact hit");
                    Destroy(gameObject);
                }
            }
        }
    }
    public void DestoryView()
    {
        Collisionentity.RemoveBaseView();
        Destroy(gameObject);
    }

    public string GetName()
    {
        return name;
    }

    public string GetTag()
    {
        return tag;
    }



}


